package com.express.core.controller;

import com.express.common.SysParamterUtil;
import com.express.entity.WxUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class MyController {

    private static final Logger logger = LoggerFactory.getLogger(MyController.class);
    @Autowired
    SysParamterUtil paramterUtil;
    /**
     * 个人中心
     * @param request
     * @return
     */
    @RequestMapping("toMy")
    public ModelAndView toMy(HttpServletRequest request) {
        // 测试
//        request.getSession().setAttribute("userId",16);
//        request.getSession().setAttribute("sysUserId",5);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("my");
        modelAndView.addObject("user",request.getSession().getAttribute("user")==null?new WxUser():
                request.getSession().getAttribute("user"));
        return modelAndView;
    }

    /**
     * 绑定页面
     * @param request
     * @return
     */
    @RequestMapping("bind")
    public ModelAndView bind(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("verification");
        modelAndView.addObject("user",request.getSession().getAttribute("user")==null?new WxUser():
                request.getSession().getAttribute("user"));
        return modelAndView;
    }


    /**
     * 刷新按钮过期时间
     * @param request
     * @return
     */
    @RequestMapping("refresh")
    @ResponseBody
    public String refresh(HttpServletRequest request) {
        paramterUtil.refreshParamter();
        return "刷新按钮过期时间成功";
    }
}
